package com.boss.salary.dao.impl;

import com.boss.framework.dao.BaseDaoImpl;
import com.boss.salary.constant.TableName;
import com.boss.salary.dao.IReportTimeControlDao;
import com.boss.salary.entity.ReportTimeControl;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

@Repository
public class ReportTimeControlDaoImpl extends BaseDaoImpl implements IReportTimeControlDao {

    @Override
    public ReportTimeControl getReportTimeControl(String province) {
        StringBuilder sql = new StringBuilder();
        sql.append(" select id, create_time, update_time, start_salary_time, end_salary_time from ")
                .append(TableName.REPORT_TIME_CONTROL);
        List<String> paramList = new ArrayList<>();
        if (!StringUtils.isEmpty(province)) {
            sql.append(" where mof_div_code = ?" );
            paramList.add(province);
        }
        return this.getjdbcTemplate().queryForObject(sql.toString(),new BeanPropertyRowMapper<>(ReportTimeControl.class),paramList.toArray());
    }

    @Override
    public void updateReportTimeControl(ReportTimeControl reportTimeControl) {
        StringBuilder sql = new StringBuilder();
        sql.append("update ").append(TableName.REPORT_TIME_CONTROL).append(" set")
           .append(" create_time=?, update_time=?, start_salary_time=?, end_salary_time=? where id=?");
        Object[] params = new Object[]{
                reportTimeControl.getCreateTime(),reportTimeControl.getUpdateTime(),reportTimeControl.getStartSalaryTime(),
                reportTimeControl.getEndSalaryTime(),reportTimeControl.getId()
        };
        this.getJdbcTemplate().update(sql.toString(), params);
    }
}
